import request from '@/api/axios.js'

//获取adcode编码
export const getAdcode=(ip)=>{
    if(ip===''){
        return request({
            url:'/ip?&key=a98a31ab207fc24d8eba7537ef3a6fe7',
            method:'get'
        })
    }else{
        return request({
            url:`/ip?ip=${ip}&key=a98a31ab207fc24d8eba7537ef3a6fe7`,
            method:'get',
            params:{
                ip:ip
            }
        })
    }
}
//通过adcode获取天气信息
export const getWeatherByAdcode=(adcode,extensions)=>{
    
    if(extensions==='base'){
        return request({
            url:`weather/weatherInfo?city=${adcode}&key=a98a31ab207fc24d8eba7537ef3a6fe7&extensions=base`,
            method:'get',
            params:{
                adcode:adcode,
                extensions:extensions
            }
        }) 
    }
    else{
        return request({
            url:`weather/weatherInfo?city=${adcode}&key=a98a31ab207fc24d8eba7537ef3a6fe7&extensions=all`,
            method:'get',
            params:{
                adcode:adcode,
                extensions:extensions
            }
        }) 
    }
    
}
//通过城市名获取adcode
export const getAdcodeByCityName=(cityName)=>{
    return request({
        url:`/geocode/geo?address=${cityName}&key=a98a31ab207fc24d8eba7537ef3a6fe7`,
        method:'get',
        params:{
            address:cityName
        }
    })
}